import json
# 读取配置文件，返回配置字典对象
def readConfig():
    with open("config.json", 'r') as load_f:
        load_dict = json.load(load_f)
        return load_dict

w = readConfig()

width = int(w['frame_width'])
height = int(w['frame_height'])
def transform(arr):
    bins = []
    temp = ''
    i = 0
    
    for x in arr:
        i = i + 1
        a = bin(x).replace('0b', '')

        while len(a) < 8:
            a = '0'+a
        a = reversed(a)
        s = ''
        for q in a:
            s = s + q
        
        temp = temp + s
        
        if i == int(width/8):
            #
            bins.append(temp)
            temp = ''
            i = 0
    return bins

#8位数据压缩
#1,1,1,1,1,1,1,1,1,1,1(128位，即oled一行)
#....
#....
#....
#....(8列)
#按竖向取8个放在元组中,元组为128个,放在列表s中


def get_num(tup):
    s = '0b'
    tup = reversed(tup)
    for x in tup:
        s = s + x
    return int(s,2)

def get(s):
    l = []
    #求每个元组的大小
    i = 0
    for x in s:
        i = i+1
        r = get_num(x)
        l.append(r)
    return l


def give(arr):
    d = transform(arr)
    ll = []
    for x in range(int(height/8)):
        g = get(zip(*d[0 + x * 8:8 + x * 8]))
        ll.extend(g)
    return ll









































